package com.imooc.spark

import org.apache.spark.sql.SparkSession

/**
 * Parquet文件操作
 */
object ParquetApp {

  def main(args: Array[String]): Unit = {
    //1)创建SparkSession对象
    val spark = SparkSession
      .builder()
      .appName("ParquetApp")
      .master("local[2]")
      .getOrCreate()

    val path = "file:///D:\\CodingFiles\\IdeaProjects\\ImoocSparkSQLProject\\data\\users.parquet"
    /**
     * spark.read.format("parquet").load 这是标准写法
     */
    val userDF = spark.read.format("parquet").load(path)

    userDF.printSchema()
    userDF.show()


    userDF.select("name", "favorite_color").show()


//    val dsnPath = "file:///D:\\CodingFiles\\IdeaProjects\\ImoocSparkSQLProject\\data\\users.json"
//    userDF.select("name", "favorite_color").write.format("json").save(dsnPath)


    spark.read.load("file:///D:\\CodingFiles\\IdeaProjects\\ImoocSparkSQLProject\\data\\users.parquet").show

    //会报错，因为sparksql默认处理的format就是parquet
//    spark.read.load("file:///D:\\CodingFiles\\IdeaProjects\\ImoocSparkSQLProject\\data\\people.json").show

    spark.read.format("parquet").option("path","file:///D:\\CodingFiles\\IdeaProjects\\ImoocSparkSQLProject\\data\\users.parquet").load().show

    spark.stop()



  }


}
